package com.apache.funds.service.plugins;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.cache.util.Validator;
import com.apache.funds.manager.SvmCaptionBalanceManager;
import com.apache.funds.util.Constants;
import com.apache.funds.vo.UserFundsVo;
import com.apache.tools.DateUtils;
import com.apache.tools.DateUtils.FmtStr;

/**
 * 本类主要涉及业务逻辑<br>
 * 1.我的资金情况（返回各个科目的实时期初+发生的余额）
 */
public class MyFundsClientPlugin implements PluginConnector {

	private SvmCaptionBalanceManager svmCaptionBalanceManager;

	@Override
	public Object execute(ParamsVo vo) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("tradeDate", DateUtils.getDate());
		long time = DateUtils.getDate().getTime();
		String dateTime = DateUtils.longToStr(time, FmtStr.yyyyMMdd);
		long dateTrade = DateUtils.toLong(DateUtils.parse(dateTime));
		vo.setParams("dateTrade", dateTrade);
		Date d = DateUtils.fromLong(dateTrade);
		Date yd = DateUtils.beforeNDays(d, 1);
		long dateTradeYesterday = DateUtils.toLong(yd);
		vo.setParams("dateTradeYesterday", dateTradeYesterday);
		ResultEntity re = new ResultEntity();
		re.setResult("true");
		if (Validator.isEmpty(vo.getParams("userId"))) {
			re.setMessage(Constants.Msg.F003+",用户ID不能为空");
			re.setResult("false");
			re.setEntity("");
			return re;
		}
		List<UserFundsVo> list = (List<UserFundsVo>) svmCaptionBalanceManager.execute(vo);
		if (list == null || list.isEmpty()) {
			re.setMessage(Constants.Msg.F001+",没有查到对象");
			re.setResult("false");
			re.setEntity("");
			return re;
		}
		re.setEntity(list);
		re.setMessage(Constants.Msg.F000);
		return re;
	}

	public void setSvmCaptionBalanceManager(SvmCaptionBalanceManager svmCaptionBalanceManager) {
		this.svmCaptionBalanceManager = svmCaptionBalanceManager;
	}

}
